
****************************************************************************
*** Replication file for
*** Däubler and Ó Muineacháin:
*** Millstone or means to succeed - 
*** Party brand value, intra-party competition and personal vote-seeking ***
*** JEPOP
****************************************************************************

version 15
set more off

* set working directory
cd "C:\Users\Thomas\Dropbox\LeafletsProject\Data\Replication"

use replication_anon.dta, clear

* define control variables
global mycont  "popdens_lo popdens_mid  distdub_gr80 loweredu_gr30 crossco front  incback senator councillor female"
global mycont2  "popdens_lo popdens_mid  distdub_gr80 loweredu_gr30 crossco  female"



*****************************************************************
*** Table 2: Intra-party competition within FG and FF in 2011 ***
*****************************************************************

 
tab ipc_max ff, col, if obsindex == 1 // keep only one obs per party-constituency
* simplification and rounding was done 'manually'



*******************************************************
*** Figure 1: Focus of candidate leaflets, by party ***
*******************************************************

gr hbox indvspty , over(party)   ylabel(-100 -50 to 100) ///
		ytitle("<== Party focus (-) to individual focus (+) ==>", margin(medium)) ///
		asyvars box(1,color("12 152 72")) ///
		box(2,color("18 86 159")) marker(1,mcolor("12 152 72")) ///
		marker(2,mcolor("18 86 159")) graphregion(fcolor(white))
gr export Figure1.eps, replace


*************************************************************************************
*** Table 3: Regression analysis of personal vs. party focus in campaign leaflets ***
*************************************************************************************


reg indvspty ipc_max $mycont  [aw=N_leaflets], cluster(pcid)
est sto m1

reg indvspty ipc_max rmate  $mycont [aw=N_leaflets], cluster(pcid)
est sto m1r

reg indvspty ff  $mycont [aw=N_leaflets], cluster(pcid)
est sto m2

reg indvspty  ipc_max rmate ff  $mycont [aw=N_leaflets], cluster(pcid)
est sto m3r

reg indvspty ipc_max rmate ff [aw=N_leaflets],  cluster(pcid)
est sto m3rbi

est table m1 m1r m2 m3r m3rbi, star


********************************************************************************************
*** Figure 2: Reported campaign aim in 2007 (10 = most personal, 0 = most party focused) ***
********************************************************************************************

* requires Comparative Candidate Survey data available here:
* data from: https://forsbase.unil.ch/project/study-public-overview/17220/0/
* then run the R script replication_prepare_CCS.R


use CCS_replication.dta, clear

tab ivsp ff, col 

* reverse scale and re-assign original values, for plotting
gen ivsprev = 10 - ivsp
lab def rev 0 "10" 1 "9" 2 "8" 3 "7" 4 "6" 5 "5" 6 "4" 7 "3" 8 "2" 9 "1" 10 "0"
lab val ivsprev rev
lab var ivsprev "Party (low) to personal (high) focus of campaign"



* this needs a bit of a workaround, since there are no candidates in the "1" category in FG
assert _N == 80
set obs 81
count if pa == "FF" & ivsprev != .
gen weight = 100/r(N) if ivsprev != . // FF. (for percentages)
count if pa == "FG" & ivsprev != .
replace weight = 100/r(N) if ivsprev != . & pa == "FG"
replace pa = "FG" in 81
replace ivsprev = 9 in 81 // this is a 1 (see reversal code above)
replace weight = 0 in 81
tab pa weight, m
byso pa: egen tmp = total(weight)
assert tmp == 100
drop tmp


						
gr hbar (sum) weight, over(ivsprev) ///
						ylabel(0(5)40, gmax)  ///
						l1title("Party (low) to personal (high) focus of campaign") ///
						ytitle("") , if pa == "FF", title("FF") bar(1,color("12 152 72")) ///
						graphregion(fcolor(white))
gr save g1, replace
gr hbar (sum) weight, over(ivsprev) ///
					  ylabel(0(5)40, gmax) ///
					  ytitle("") , if pa == "FG", title("FG") bar(1,color("18 86 159")) ///
					  graphregion(fcolor(white))
gr save g2, replace
gr combine g1.gph g2.gph, rows(1)  xcommon ycommon ///
							b1title("% in party") graphregion(fcolor(white))
gr export Figure2.eps, replace
erase "g1.gph" 
erase "g2.gph"


********************************************************************
*** Table A-1.1 Comparing in-sample and out-of-sample candidates ***
********************************************************************

use replication_anon.dta, clear

foreach v of var ipc* rmate $mycont elected quota1st {
di as error "`v'"
ttest `v', by(insample) uneq, if ff == 0
ttest `v', by(insample) uneq, if ff == 1
}

***************************************************************************************************************
*** Table A-1.2 Explaining electoral performance within FG using the control variables of the main analysis ***
***************************************************************************************************************

logit elected  ipc_max rmate $mycont if ff == 0
est store fg1
reg quota1st  ipc_max  rmate $mycont if ff == 0
est store fg2

est table fg*, star

* compare campaign focus of elected vs unelected FG candidates in sample (reported in text)
ttest indvspty, by(elected) uneq, if ff == 0

********************************************************************************
*** Table A-2.2: Concordance-correlation between results by coders (overall) ***
********************************************************************************

use replication_intercoder_anon.dta, clear

foreach v in "perc1*" "perc2*" "perc3*" "perc4*" "perc5*" "perc6*" "perc7*" "perc8*" "perc9*"  {
di as error "Category: `v'"
concord `v' 
}

foreach v in "ind*" "par*" "loc*" "nat*" "d1neut*" "d2neut*"    {
di as error "Category: `v'"
concord `v' 
}

foreach v in  "ivsp*"  "lvsn*"  {
di as error "Category: `v'"
concord `v' 
}

************************************************************************************************
*** Table A-2.3: Concordance-correlation between results by coders (split by party, FG | FF) ***
************************************************************************************************


foreach v in "perc1*" "perc2*" "perc3*" "perc4*" "perc5*" "perc6*" "perc7*" "perc8*" "perc9*"  {
di as error "Category: `v'"
di as error "--- FG ---"
concord `v'  if ff == 0
di as error "--- FF ---"
concord `v'  if ff == 1
}

foreach v in "ind*" "par*" "loc*" "nat*" "d1neut*" "d2neut*"    {
di as error "Category: `v'" 
di as error "--- FG ---"
concord `v'  if ff == 0
di as error "--- FF ---"
concord `v'  if ff == 1
}

foreach v in  "ivsp*"  "lvsn*"  {
di as error "Category: `v'"
di as error "--- FG ---"
concord `v'  if ff == 0
di as error "--- FF ---"
concord `v'  if ff == 1
}

***************************************************************************************
*** Figure A-2.1: Comparison of coder ratings on personal vs. party focus, by party ***
***************************************************************************************

tw sc ivspSecond ivspMain if ff == 0, msym(circle_hollow) mcol(blue) ///
	ytit("Second coder") xtit("Main coder") aspectratio(1) || ///
	sc ivspSecond ivspMain if ff == 1, msym(0) mcol(green)  || ///
	function y=x, range(-100 100) lcol("grey") lpatt("dash") legend(off) scheme(s2mono)

	gr export FigureA21.emf, replace



*****************************************
*** Table A-3.1: Summary of variables ***
*****************************************

use replication_anon.dta, clear


gen popdens_hi = 1 - popdens_lo - popdens_mid


sum indvspty locvsnat indvspty_noshared locvsnat_noshared ///
									ff  ipc_max ipc_tal ipc_kav ipc_nta	rmate  ///
									crossco popdens_*  loweredu_gr30 distdub_gr80 ///
									 incback front  senator councillor female if insample
drop popdens_hi									 

****************************************************************************************************
*** Table A-4.1: Regression results for dependent variable considering only non-shared documents ***
****************************************************************************************************


reg indvspty_noshared  ipc_max  $mycont [aw=N_leaflets_noshared], cluster(pcid)
est sto mn1

reg indvspty_noshared  ipc_max rmate  $mycont [aw=N_leaflets_noshared], cluster(pcid)
est sto mn1r

reg indvspty_noshared ff  $mycont [aw=N_leaflets_noshared], cluster(pcid)
est sto mn2

reg indvspty_noshared ff ipc_max rmate $mycont [aw=N_leaflets_noshared], cluster(pcid)
est sto mn3r

reg indvspty_noshared ipc_max rmate ff [aw=N_leaflets_noshared],  cluster(pcid)
est sto mn3rbi

est table mn1 mn1r mn2 mn3r mn3rbi, star


*******************************************************************************************
*** Figure A-5.1: Candidate-type-specific marginal effects (including shared documents) ***
*******************************************************************************************


gen candtype = 0
replace candtype = 1 if councillor == 1 
replace candtype = 2 if incback == 1
replace candtype = 3 if senator == 1 
replace candtype = 4 if front == 1
lab def ct 0 "No office" 1 "Councillor" 2 "Backbench TD" 3 "Senator" 4  "Frontbench"
lab val candtype ct

reg indvspty i.ff##i.candtype ipc_max  rmate $mycont2 [aw=N_leaflets], cluster(pcid)


margins candtype, dydx(ff)
marginsplot, recast(scatter)  horizontal ///
		xtitle("Difference FF vs. FG" "on personal vs. party dimension") ytitle("") title("") scheme("s2mono") ///
		xline(0, lpatt(dash)) xlabel(-50(50)150) yscale(r(-.5 4.5))
			
gr export FigureA51.emf,  replace

		
*****************************************************************************************
*** Figure A-5.2: Candidate-type-specific marginal effects (without shared documents) ***
*****************************************************************************************

reg indvspty_noshared i.ff##i.candtype  ipc_max  rmate $mycont2  [aw=N_leaflets_noshared], cluster(pcid)
count if ff == 1 & front == 0 & incback == 0 & senator == 0 & councillor == 0 & e(sample)
count if ff == 0 & front == 0 & incback == 0 & senator == 0 & councillor == 0 & e(sample)

margins candtype, dydx(ff)
marginsplot, recast(scatter)  horizontal ///
			xtitle("Difference FF vs. FG" "on personal vs. party dimension") ytitle("") title("") scheme("s2mono") ///
			xline(0, lpatt(dash)) xlabel(-50(50)150) yscale(r(-.5 4.5))

gr export FigureA52.emf,  replace

			
******************************************************************************************************************************************
*** Table A-6.1: Regression results with alternative measures of intra-party competition (dependent variable considers all documents)  ***
******************************************************************************************************************************************

foreach v of var  ipc_kav ipc_tal ipc_nta {

reg indvspty ff `v' rmate  $mycont [aw=N_leaflets], cluster(pcid)
est sto m`v'
reg indvspty_noshared ff `v' rmate $mycont [aw=N_leaflets_noshared], cluster(pcid)
est sto mns`v'
}

est table m3r  mipc*, star

*****************************************************************************
*** Figure A-7.1 Local vs. national focus of candidate leaflets, by party ***
*****************************************************************************

gr hbox locvsnat , over(party)   ylabel(-100 -50 to 100) ///
		ytitle("<== National focus (-) to local focus (+) ==>", margin(medium)) ///
		asyvars box(1,color("12 152 72")) ///
		box(2,color("18 86 159")) marker(1,mcolor("12 152 72")) ///
		marker(2,mcolor("18 86 159")) graphregion(fcolor(white))
gr export FigureA71.emf, replace


***************************************************************************************
*** Table A-7.1 Regression analysis of local vs national focus in campaign leaflets ***
***************************************************************************************

reg locvsnat ipc_max $mycont  [aw=N_leaflets], cluster(pcid)
est sto l1

reg locvsnat ipc_max rmate  $mycont [aw=N_leaflets], cluster(pcid)
est sto l1r

reg locvsnat ff  $mycont [aw=N_leaflets], cluster(pcid)
est sto l2

reg locvsnat  ipc_max rmate ff  $mycont [aw=N_leaflets], cluster(pcid)
est sto l3r

reg locvsnat ipc_max rmate ff [aw=N_leaflets],  cluster(pcid)
est sto l3rbi

est table l*, star

***************************************************************************
*** Table A-8.1: Results from regression model of candidate survey data ***
***************************************************************************

* requires Comparative Candidate Survey data available here:
* data from: https://forsbase.unil.ch/project/study-public-overview/17220/0/
* then run the R script replication_prepare_CCS.R


use CCS_replication.dta, clear

reg ivsp ff, rob
est sto mccs1

reg ivsp  ff   rmate   i.percmarg   councillor i.townsize    female, rob
est sto mccs2

est table mccs*, star
